package djboom.materials.display.devices {
	import djboom.materials.core.BitmapDataCore;
	import djboom.materials.display.elements.SimpleSmartSprite;

	import com.greensock.TweenLite;
	import com.greensock.easing.Linear;

	import org.casalib.display.CasaBitmap;
	import org.casalib.display.CasaShape;

	import flash.display.MovieClip;
	import flash.events.Event;

	/**
	 * Прибор Ле-Шателье.
	 * <br>
	 * 
	 * @author DJ BooM 
	 * @since 01.02.2011
	 * 
	 */

	public class FlaskLeChatelier extends SimpleSmartSprite {

		// ----------------------------------------------------------------------------
		// Константы класса.
		// ----------------------------------------------------------------------------

		private static const BACK:String = "flaskLeChatelier.Back";		private static const BORDER:String = "flaskLeChatelier.Border";		private static const MARKING:String = "flaskLeChatelier.Marking";		private static const WATER_MASK:String = "flaskLeChatelier.WaterMask";

		// ----------------------------------------------------------------------------
		// Свойства класса.
		// ----------------------------------------------------------------------------

		private var _backBitmap:CasaBitmap;
		private var _borderBitmap:CasaBitmap;
		private var _waterMask:MovieClip;
		private var _waterShape:CasaShape;
		private var _markingBitmap:CasaBitmap;

		private var _absoluteAmountSample:Number;

		
		
		// ----------------------------------------------------------------------------
		// Конструктор.
		// ----------------------------------------------------------------------------

		public function FlaskLeChatelier() {
			super();
			
			_backBitmap = new CasaBitmap(BitmapDataCore.getBitmapData(BACK));
			_backBitmap.x = 2;			_backBitmap.y = 1;
			addChild(_backBitmap);
            
			_waterShape = new CasaShape();
			_waterShape.y = 301;
			_waterShape.graphics.beginFill(0x008DEF, 0.4);
			_waterShape.graphics.drawRect(0, 0, 69, 302);
			_waterShape.graphics.endFill();
			addChild(_waterShape);
            
			_waterMask = BitmapDataCore.getMovieClip(WATER_MASK);
			_waterMask.x = 2;			_waterMask.y = 1;
			addChild(_waterMask);
            
			_waterShape.mask = _waterMask;
			
			_borderBitmap = new CasaBitmap(BitmapDataCore.getBitmapData(BORDER));
			addChild(_borderBitmap);
			
			_markingBitmap = new CasaBitmap(BitmapDataCore.getBitmapData(MARKING));
			_markingBitmap.x = 28;
			_markingBitmap.y = 40;
			addChild(_markingBitmap);
		}

		// ----------------------------------------------------------------------------
		// Приватные методы класса.
		// ----------------------------------------------------------------------------
			
		// ----------------------------------------------------------------------------
		// Видимые методы класса.
		// ----------------------------------------------------------------------------
		
		// ----------------------------------------------------------------------------
		// Переопределенные методы.
		// ----------------------------------------------------------------------------

		override public function clearContent(event:Event):void {
			super.clearContent(event);
		}

		
		// ----------------------------------------------------------------------------
		// Обработчики событий.
		// ----------------------------------------------------------------------------
		
		// ----------------------------------------------------------------------------
		// Публичные методы.
		// ----------------------------------------------------------------------------

		public function filledWater():void {
			TweenLite.to(_waterShape, BottleOfWater.TIMER_OPEN_WATER, {y: 164, delay: 0.6, ease: Linear.easeNone});
		}

		public function animateWater():void {
			var pointY:Number = 100 - ((_absoluteAmountSample-20)*20);
			
			TweenLite.to(_waterShape, 2, {y: pointY, ease: Linear.easeNone});
		}

		// ----------------------------------------------------------------------------
		// Методы доступа.
		// ----------------------------------------------------------------------------

		public function set absoluteAmountSample(i:Number):void {
			_absoluteAmountSample = i;
		}
	}
}
